package cn.lingyangwl.agile.misc.statistic;

import cn.lingyangwl.agile.misc.statistic.constant.*;
import cn.lingyangwl.agile.misc.statistic.model.*;
import cn.lingyangwl.framework.core.response.Resp;
import cn.lingyangwl.framework.core.response.RetOps;
import cn.lingyangwl.framework.tool.core.exception.BizException;
import com.alibaba.cloud.nacos.NacosServiceAutoConfiguration;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author shenguangyang
 */
@Service
@ConditionalOnClass({FeignAutoConfiguration.class, NacosServiceAutoConfiguration.class})
public class StatisticApiCloudImpl implements StatisticApi {
    @Resource
    private RemoteStatisticService service;
    @Resource
    private RabbitTemplate rabbitTemplate;


    @Override
    public void syncTask() {
        Resp<?> resp = service.syncTask();
        RetOps.of(resp).assertSuccess(e -> new BizException(e.getCode(), e.getMsg()));
    }

    @Override
    public void sendMsg(StatisticBaseReq req) {
        rabbitTemplate.convertAndSend(StatisticCons.EXCHANGE, req.getName(), req.toMessage());
    }
}
